import router from '@system.router';

export default {
    data: {
        items: [
        ],
        yuan: 0,
        fen: ".00",
        sum: 0,
        class:""
    },
    onInit() {
      this.fetch();
    },
    go(path) {
        router.push({ uri: path });
    },
    fetch() {
        let classes = ["芭比粉", "金属银", "拉丝黑"]
        for (let i = 1; i <= 3; i++) {
            this.items.push(
                {
                    mall: "败家实验室",
                    name: "败家实验室 流水风刃 三菱黑武士SXN1000 金属中油笔防疲劳中性笔",
                    yuan: 61,
                    fen: ".6",
                    price: 61.6,
                    amount: 1,
                    pic: "common/images/detail/class" + i + ".jpg",
                    class: classes[i-1]
                }
            );
        }
    },
    selectItem(i, checkbox) {
        if (checkbox.checked) {
            this.sum += this.items[i].price;
        } else {
            this.sum -= this.items[i].price;
        }
        this.parsePrice();
    },
    parsePrice() {
        this.yuan = Math.floor(this.sum);
        this.fen = "" + (this.sum - this.yuan);
        this.fen = this.fen.substr(1, 3);
    }
}
